package edu.cuit.avatar;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * InputStream:读取二进制数据的抽象基类
 *      FileInputStream
 *      FilterInputStream
 *          DataInputStream
 *          BufferedInputStream
 *      ObjectInputStream
 * OutputStream:写入二进制数据的抽象基类
 *      FileOutputStream
 *      FilterOutputStream
 *          DataOutputStream
 *          BufferedOutputStream
 *      ObjectOutputStream
 *
 * 转换流
 *      InputStreamReader
 *      OutputStream
 *
 * 内存中的字节数据
 *      ByteArrayInputStream
 *
 * @author <a href="mailto:1020zhaodan@163.com">Adan</a>
 * @version 1.0
 * @date 2025/7/12 8:51
 */
public class FileStreamDemo {
    public static void copy(File source, File dest)  {
        try(var input = new FileInputStream(source);
            var output = new FileOutputStream(dest)) {
           byte[] buffer = new byte[1024];
           int len = -1;
           while((len = input.read(buffer)) != -1) {
               output.write(buffer, 0, len);
           }
        }catch (IOException e){
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        var source = new File("D:/chapter1.txt");
        var dest = new File("chapter1.txt");
        copy(source, dest);
    }
}
